/*
 * Copyright (C) 2022, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

#ifndef UKUI_SIDEBAR_SIDE_BAR_APPLICATION_H
#define UKUI_SIDEBAR_SIDE_BAR_APPLICATION_H

#include <QObject>
#include <QUrl>
#include <QSystemTrayIcon>
#include <QAction>
#include <QMenu>
#include <QProcess>
#include <QTimer>
#include <QDBusInterface>
#include <QObject>
#include <QDBusConnection>
#include <QTranslator>

#include "qtsingleapplication.h"

class ShortcutsWindow;
namespace Sidebar {
class SidebarView;
class SidebarDbusService;
}

namespace UkuiNotification {
    class NotificationCenterWindow;
    class PopupNotificationWindow;
    class TabletPopupView;
}

class SideBarApplication : public QtSingleApplication
{
    friend class SidebarDbusService;
    Q_OBJECT
public:
    enum Request {
        Active,
        Show,
        Hide,
        DirectlyHide
    };
    explicit SideBarApplication(const QString &appId, int &argc, char **argv);
    ~SideBarApplication() override;

public Q_SLOTS:
    void requestSidebar(SideBarApplication::Request request);
    void requestNotificationCenter(SideBarApplication::Request request);

private Q_SLOTS:
    void loadTabletWindows();

private:
    void startSidebar();

    void parseCommand(const QString &msg, bool isPrimary);
    static void registerItems();

    inline void initPublicObjects();
    void loadQML();
    //系统托盘 设置menu界面、添加动作 和 创建systray实例
    void createSystray();
    void updateSystrayIcon(bool clearRedPoint = true);

    void initSidebar();
    void initShortcut();
    void initNotificationCenter();
    void initPopupWindow();
    void initTabletPopupWindow();

private:
    Sidebar::SidebarView *m_sidebarWindow {nullptr};
    ShortcutsWindow *m_shortcutsWindow {nullptr};
    UkuiNotification::NotificationCenterWindow *m_notificationCenterWindow {nullptr};
    UkuiNotification::PopupNotificationWindow *m_popupNotificationWindow {nullptr};
    UkuiNotification::TabletPopupView *m_tabletPopupView {nullptr};

    // 系统托盘
    QSystemTrayIcon* m_trayIcon {nullptr};
    QMenu *m_trayIconMenu {nullptr};
};

#endif //UKUI_SIDEBAR_SIDE_BAR_APPLICATION_H
